{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import predict_ner.predict_base as ner\n",
    "import predict_DM.predict_DM as DM\n",
    "import tracker"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {},
   "outputs": [],
   "source": [
    "penultimate_intent = []\n",
    "penultimate_entities =[] \n",
    "previous_intent = []\n",
    "previous_entities = []\n",
    "current_intent = []\n",
    "current_entities = []\n",
    "\n",
    "penultimate_action = []\n",
    "previous_action = []\n",
    "current_action = []\n",
    "\n",
    "transfer_intent = []\n",
    "transfer_entitites= []\n",
    "transfer_action = []"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- interpreter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "intent:Control-Lamp_Close \n",
      " slot:{'operation': '关', 'device': '灯'}\n"
     ]
    }
   ],
   "source": [
    "intent,entities,entities_dic = ner.predict('关灯')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['operation', 'device']"
      ]
     },
     "execution_count": 141,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "entities"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- interpreter_trackerguanbi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "penultimate_intent:  ['Control-Lamp_Open']\n",
      "penultimate_entities:  ['operation', 'device', 'address']\n",
      "previous_intent:  ['Control-Lamp_Lightness']\n",
      "previous_entities:  ['address', 'target', 'operation', 'device']\n",
      "current_intent:  ['Control-Lamp_Close']\n",
      "current_entities:  ['operation', 'device']\n",
      "transfer_intent :  ['Control-Lamp_Close', 'Control-Lamp_Lightness', 'Control-Lamp_Open']\n",
      "transfer_entitites :  {'operation', 'target', 'device', 'address'}\n"
     ]
    }
   ],
   "source": [
    "current_intent,current_entities,previous_intent,previous_entities,penultimate_intent,penultimate_entities,transfer_entitites, transfer_intent=tracker.entities_tracker(intent,entities,current_intent,current_entities,\\\n",
    "                     previous_intent,previous_entities,penultimate_intent,penultimate_entities)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "metadata": {},
   "outputs": [],
   "source": [
    "trackers = tracker.tracker(transfer_action,transfer_entitites,transfer_intent)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- policy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "　text: [['action_controllamplightness'], ['operation', 'target', 'device', 'address'], ['Control-Lamp_Close', 'Control-Lamp_Lightness', 'Control-Lamp_Open']] \n",
      " action:action_close_lamp \n",
      " \n"
     ]
    }
   ],
   "source": [
    "action  = DM.predict(trackers)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "-nlu- action_trackeracmode_form"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "penultimate_action:  []\n",
      "previous_action:  []\n",
      "current_action:  ['action_close_lamp']\n",
      "transfer_action :  ['action_close_lamp']\n"
     ]
    }
   ],
   "source": [
    "kongtiaocurrent_action,previous_action,penultimate_action, transfer_action = tracker.action_tracker(action,current_action,previous_action,penultimate_action)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "metadata": {},
   "outputs": [],
   "source": [
    "trackers = tracker.tracker(transfer_action,transfer_entitites,transfer_intent)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[['action_close_lamp'],\n",
       " ['operation', 'target', 'device', 'address'],\n",
       " ['Control-Lamp_Close', 'Control-Lamp_Lightness', 'Control-Lamp_Open']]"
      ]
     },
     "execution_count": 147,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "trackers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
